package logic

import (
	"context"
	"order/orderrpc/internal/models"

	"order/orderrpc/internal/svc"
	"order/orderrpc/pb/orderrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateOrderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrderLogic {
	return &CreateOrderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CreateOrderLogic) CreateOrder(in *orderrpc.CreateOrderRequest) (*orderrpc.CreateOrderResponse, error) {
	// todo: add your logic here and delete this line
	err := models.CreateOrder(in.Name, int(in.Num))
	if err != nil {
		return &orderrpc.CreateOrderResponse{
			Code: 400,
			Msg:  err.Error(),
		}, nil
	}
	return &orderrpc.CreateOrderResponse{
		Code: 200,
		Msg:  "订单生成成功，请尽快付款",
	}, nil
}
